/**
 * @file message_utils.h
 * @author 王烨
 * @date 2011-01-09
**/
#ifndef MESSAGE_UTILS_INCLUDED_H
#define MESSAGE_UTILS_INCLUDED_H

#include <string>

#include <uuid/uuid.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>

namespace skeleton
{
  /*客户端序列化发送的RPC请求*/
  std::string SerializeRequest(const google::protobuf::MethodDescriptor &descriptor,
			       const google::protobuf::Message &parameters);
  void SerializeRequest(const google::protobuf::MethodDescriptor &descriptor,
			const google::protobuf::Message &parameters,
			std::string &requestData);
  void SerializeRequest(const google::protobuf::MethodDescriptor &descriptor,
			const google::protobuf::Message &parameters,
			void *requestData,
			int length);
  /*服务端序列化发送的RPC响应*/
  std::string SerializeResponse(const uuid_t &uuid,
				const google::protobuf::Message &message,
				bool isErrorMessage = false);
  void SerializeResponse(const uuid_t &uuid,
			 const google::protobuf::Message &message,
			 std::string &responseData,
			 bool isErrorMessage = false);
  void SerializeResponse(const uuid_t &uuid,
			 const google::protobuf::Message &message,
			 void *responseData,
			 int length,
			 bool isErrorMessage = false);
  /*服务端反序列化接收的RPC请求*/
  void DeserializeRequest(const std::string &requestData,
			  uuid_t &uuid,
			  std::string &serviceName,
			  std::string &methodName,
			  google::protobuf::Message &parameters);
  void DeserializeRequest(void *requestData,
			  int length,
			  uuid_t &uuid,
			  std::string &serviceName,
			  std::string &methodName,
			  google::protobuf::Message &parameters);
  /*客户端反序列化接收的RPC响应*/
  void DeserializeResponse(const std::string &responseData,
			   uuid_t &uuid,
			   google::protobuf::Message &result);
  void DeserializeResponse(void *responseData,
			   int length,
			   uuid_t &uuid,
			   google::protobuf::Message &result);
}
#endif
